<?php
defined('IN_ADMIN') or exit('No permission resources.');
include $this->admin_tpl('header_simple', 'admin');
?>
<div class="pad-lr-10">
    <form name="myform" action="?m=formguide&c=formguide_info&a=delete" method="post">
        <div class="table-list">
            <table width="100%" cellspacing="0">
                <thead>
                    <tr>
                        <th width="35" align="center"><input type="checkbox" value="" id="check_box" onclick="selectall('did[]');"></th>
                        <th width='100' align="center" align="center">姓名</th>
                        <th width='250' align="center">电话</th>
                        <th width="250" align="center">留言主题</th>
                        <th width="150" align="center">留言时间</th>
                        <th width="250" align="center">回复部门</th>
                        <th width="80" align="center">回复状态</th>
                        <th width="80" align="center">操作</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    if (is_array($datas)) {
                        foreach ($datas as $d) {
                            ?>   
                            <tr>
                                <td align="center">
                                    <input type="checkbox" name="did[]" value="<?php echo $d['dataid'] ?>">
                                </td>
                                <td align="center"><?php echo $d['name'] ?> </td>
                                <td align="center"><?php echo $d['mobile'] ?></td>
                                <td align="center"><?php echo $d['subject'] ?></td>
                                <td align="center"><?php echo date('Y-m-d H:i:s',$d['datetime']) ?></td>
                                <td align="center"><?php echo empty($grouplist[$d['groupid']]) ? "-" : $grouplist[$d['groupid']] ?></td>
                                 <td align="center">
                                    <?php
                                    if(empty($d['replay'])) {
                                        echo '<font style="color:red;">未回复</font>';
                                    }else {
                                        echo "已回复";
                                    }
                                    ?>
                                </td>
                                <td align="center">
                                    <a href="javascript:check('<?php echo $formid ?>', '<?php echo $d['dataid'] ?>', '<?php echo safe_replace($d['username']) ?>');void(0);"><?php echo L('check') ?></a> | 
                                    <a href="?m=formguide&c=formguide_info&a=public_delete&formid=<?php echo $formid ?>&did=<?php echo $d['dataid'] ?>" onClick="return confirm('<?php echo L('confirm', array('message' => '留言')) ?>')"><?php echo L('del') ?></a>
                                </td>
                            </tr>
                            <?php
                        }
                    }
                    ?>
                </tbody>
            </table>

            <div class="btn"><label for="check_box"><?php echo L('selected_all') ?>/<?php echo L('cancel') ?></label>
                <input name="submit" type="submit" class="button" value="<?php echo L('remove_all_selected') ?>" onClick="document.myform.action = '?m=formguide&c=formguide_info&a=public_delete&formid=<?php echo $formid ?>';
                        return confirm('<?php echo L('affirm_delete') ?>')">&nbsp;&nbsp;</div>  </div>
            <div id="pages"><?php echo $pages; ?></div>
    </form>
</div>
</body>
</html>
<script type="text/javascript">
    function check(id, did, title) {
        window.top.art.dialog({id: 'check'}).close();
        window.top.art.dialog({
            title: '<?php echo L('check') ?> -- ' + title + '留言内容', 
            id: 'check', 
            iframe: '?m=formguide&c=formguide_info&a=public_view&formid=' + id + '&did=' + did, 
            width: '600px', 
            height: '400px',
            button:[{
                name: '保存',
                focus: true,
                callback: function() {
                    var dialog = this;
                    // 获取回复内容
                    
                    var iframe = this.content().firstChild;
                    var replay = $(iframe.contentDocument.getElementById('replay')).val();
                    var groupid = $(iframe.contentDocument.getElementById('groupid')).val();
                    
                    if($.trim(replay) === '') {
                        Alert('请输入回复内容！', '<?php echo IMG_PATH?>icon/alert.png');
                        return false;
                    }
                    if($.trim(groupid) === '' || groupid == -1) {
                        Alert('请选择回复部门！', '<?php echo IMG_PATH?>icon/alert.png');
                        return false;
                    }
                    
                    // 保存回复内容
                    
                    $.ajax({
                        url: '?m=formguide&c=formguide_info&a=public_save_replay',
                        type: "POST",
                        data: {"formid":id, "did":did, "replay":replay, "groupid":groupid},
                        dataType: "JSON",
                        beforeSend: function() {
                            Alert("正在保存...", '<?php echo IMG_PATH?>loading.gif');
                        },
                        success: function(data) {
                            if(data && data.status) {
                                dialog.close();
                                window.top.art.dialog({id: 'alert'}).close();
                                window.location.reload();
                            }else if(data && data.status == false) {
                                Alert(data.info, '<?php echo IMG_PATH?>icon/alert.png');
                            }else {
                                Alert("网络异常，请联系管理员！", '<?php echo IMG_PATH?>icon/alert.png');
                            }
                        },
                        error: function() {
                            Alert("网络异常，请联系管理员！", '<?php echo IMG_PATH?>icon/alert.png');
                        }
                    });
                    
                    return false;
                }
            },{
                name: '关闭',
                focus: false
            }]
        });
    }
</script>